from django.urls import path
from rest_framework.routers import SimpleRouter

# from .views import ProductCategoryCreateView, DishCategoryCreateView, ProductCreateView, DishCreateView
from . import views
from .views import CommodityListCreateView, CommodityRetrieveUpdateDestroyView, ProductSearchAPIView, InventoryViewSet, \
    InventoryDetailView, DishSearchAPIView, BulkProductUploadView

router = SimpleRouter()
# router = SimpleRouter(trailing_slash=False)

# 菜品分类=动态路由+generic+五个扩展类的curd：http://127.0.0.1:8000/staging/dish_category/1/
router.register('dish_category', views.DishCategoryGetView, 'dish_category')

# 货品=动态路由+generic+五个扩展类的curd：http://127.0.0.1:8000/staging/product/
router.register('product', views.ProductView, 'product')
# http://127.0.0.1:8000/staging/user/login/
router.register('user', views.DishCategoryGetView, 'user')
# http://127.0.0.1:8000/staging/image/upload_image/
router.register('image', views.HeadFileView, 'image')
# http://127.0.0.1:8000/staging/sales_record/
router.register('sales_record', views.SalesRecordView, basename='sales_record')

router.register('inventory', InventoryViewSet, basename='inventory')

urlpatterns = [
    # 单位curd=基于APIView+序列化类+Response的curd：http://127.0.0.1:8000/staging/units
    path('units/', views.UnitView.as_view()),
    path('units/<int:pk>/', views.UnitDetailView.as_view()),
    # 货品信息GenericAPIView---》继承了APIView的curd： http://127.0.0.1:8000/staging/product_category
    path('product_category/', views.ProductCategoryView.as_view()),
    path('product_category/<int:pk>/', views.ProductCategoryDetailView.as_view()),
    # 菜品curd=基于GenericAPIView+5个视图扩展类写接口： http://127.0.0.1:8000/staging/dishs
    path('dishs/', views.DishView.as_view()),
    path('dishs/<int:pk>/', views.DishDetailView.as_view()),
    # 供应商=通过ModelViewSet编写5个接口的curd： http://127.0.0.1:8000/staging/suppliers
    # path('suppliers/', views.SupplierView.as_view({'get': 'list', 'post': 'create'})),
    # path('suppliers/<int:pk>/', views.SupplierView.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
    # # 供应商=通过ReadOnlyModelViewSet编写2个只读接口： http://127.0.0.1:8000/staging/suppliers_read_only
    # path('suppliers_read_only/', views.SupplierReadOnlyView.as_view({'get': 'list'})),
    # path('suppliers_read_only/<int:pk>/', views.SupplierReadOnlyView.as_view({'get': 'retrieve'})),

    # path('create/product-category/', ProductCategoryCreateView.as_view(), name='create-product-category'),
    # path('create/dish-category/', DishCategoryCreateView.as_view(), name='create-dish-category'),
    # path('create/product/', ProductCreateView.as_view(), name='create-product'),
    # path('create/dish/', DishCreateView.as_view(), name='create-dish'),
    # http://127.0.0.1:8000/staging/commodities/
    path('commodities/', CommodityListCreateView.as_view(), name='commodity-list-create'),
    path('commodities/<int:pk>/', CommodityRetrieveUpdateDestroyView.as_view(), name='commodity-detail'),

    path('search/', ProductSearchAPIView.as_view(), name='product_search'),
    path('dish_search/', DishSearchAPIView.as_view(), name='dish_search'),


    path('del_inventory/<int:pk>/', InventoryDetailView.as_view(), name='inventory-detail'),



    path('upload_products', BulkProductUploadView.as_view(), name='bulk_product_upload')

]

urlpatterns += router.urls
